import * as networkAction from '../actions/network'
import {combineReducers} from 'redux'

//网络类型
const netType =(state=1,action)=>{
    switch (action.type){
        case networkAction.TYPE_SWITCH:
            return action.data
        default:
            return state
    }
}
const networkInit = {
    ip:'',
    netmask:'',
    username:'',
    password:'',
    gateway:'',
    mac:''
}
//当前网络参数
const network =(state=networkInit,action)=>{
    switch (action.type){
        case networkAction.NET_SUBMIT_RECEIVE:
            return Object.assign({},state,action.data)
        default :
            return state
    }
}
//网络设置状态
const submitState = (state=false,action)=>{
    switch (action.type){
        case networkAction.NET_SUBMIT_START:
            return true
        case networkAction.NET_SUBMIT_RECEIVE:
            return false
        default :
            return state
    }
}

const error= (state={message:''},action)=>{
    switch(action.type){
        case networkAction.NET_SUBMIT_ERROR:
            return Object.assign({},state,{message:action.data})
        case networkAction.NET_CLEAR_ERROR:
            return Object.assign({},{message:''})
        default:
            return state
    }
}

const wan = combineReducers({
    netType,network,submitState,error
})
export default wan